<?php
/*
* Author：鑫宇工作室
* QQ：639519801
* url：www.xinyuream.com
*/
include_once $_SERVER['DOCUMENT_ROOT'].'/func/include.php';
$user=admin_check(true);
$apps=admin_apps();
$id=intval(input('id'));
$u=false;
if($id>0){
	$re=query("select * from xy_news where id='{$id}'");
	if($re){
		$u=$re[0];
	}
}
?>
<div class="layuimini-main">
    <div class="layui-form layuimini-form">
        <div class="layui-form-item">
            <label class="layui-form-label required">公告软件</label>
			<?=$u?'<input type="hidden" name="id" value="'.$id.'">':''?>
			<div class="layui-input-block">
				<select name="appid" lay-verify="required" lay-reqtext="请选择软件">
					<?for($i=0;$i<count($apps);$i++){?>
					<option value="<?=$apps[$i]['id']?>" <?=$u==false?'':($u['appid']==$apps[$i]['id']?'selected':'')?>><?=$apps[$i]['appname']?></option>
					<?}?>
				</select>
			</div>
        </div>
		<div class="layui-form-item">
            <label class="layui-form-label ">公告内容</label>
            <div class="layui-input-block">
               <textarea name="content" placeholder="请输入公告内容" class="layui-textarea" lay-verify="required"><?=$u?$u['content']:''?></textarea>
            </div>
        </div>
		<div class="layui-form-item">
            <label class="layui-form-label ">发布时间</label>
            <div class="layui-input-block">
               <input type="text" name="stime" id="date"  value="<?=$u?$u['stime']:''?>" lay-verify="datetime" placeholder="yyyy-MM-dd HH:ii:ss" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form', 'table','laydate'], function () {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table,
			laydate =layui.laydate
            $ = layui.$;
        form.render();
		laydate.render({
		  elem: '#date', //元素的id
		  type:'datetime'
		});
        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;
        //监听提交
        form.on('submit(saveBtn)', function (data) {
			$.post({
				url:'/admin?ac=<?=$u?'editnews':'addnews'?>',
				data: data.field,
				type:'post',
				dataType:'json',
				success:function(e){
					layui.exit(e);
					if(e.code===200){
						layer.msg(e.msg,{icon: 6,time: 2000});
						parent.layui.table.reload('datalist');
						layer.close(parentIndex);
					}else{
						layer.msg(e.msg,{icon: 5,time: 2000});
					}
				},
				error: function(e){
				  layer.msg('数据异常，操作失败！',{icon: 5,time: 2000});
				  
				}
			});

            return false;
        });

    });
</script>